package main

import (
	"flag"
	"mysqltools/config"
	"mysqltools/export"
)

func main() {
	var dirPath string
	var host string
	var port string
	var user string
	var passwd string
	var db string
	var useDB bool
	var createDB bool
	var lock bool
	var proc bool
	var fun bool
	var trig bool
	var view bool
	var event bool
	var all bool

	flag.StringVar(&dirPath, "d", ".", "保存路径, 默认当前目录")
	flag.StringVar(&host, "h", "localhost", "数据库地址，默认localhost")
	flag.StringVar(&port, "p", "3306", "数据库端口，默认3306")
	flag.StringVar(&user, "u", "root", "用户名，root")
	flag.StringVar(&passwd, "a", "123456", "密码，123456")
	flag.StringVar(&db, "b", "test", "db名称，默认 test")
	flag.BoolVar(&createDB, "-create-db", true, "是否包含 create-db语句，默认 true")
	flag.BoolVar(&useDB, "-use-db", true, "是否包含 use db语句，默认 true")
	flag.BoolVar(&lock, "-lock", false, "insert 是否包含 lock语句，默认 false")
	flag.BoolVar(&proc, "-proc", true, "是否备份 procedure，默认 true")
	flag.BoolVar(&fun, "-func", true, "是否备份 function，默认 true")
	flag.BoolVar(&trig, "-trig", true, "是否备份 trigger，默认 true")
	flag.BoolVar(&view, "-view", true, "是否备份 view，默认 true")
	flag.BoolVar(&event, "-event", false, "是否备份 event，默认 false")
	flag.BoolVar(&all, "-all", false, "是否备份 event，默认 false")
	//解析命令行参数，写入注册的flag里面
	flag.Parse()
	conf := config.DBConfig{Host: host, Port: port, Username: user, Password: passwd, Database: db}
	option := export.Option{Path: dirPath, IsCreateDB: createDB, IsUseDB: useDB, IsInsertLock: lock, IsProc: proc, IsFunc: fun, IsTrig: trig, IsEvent: event, IsView: view, AllData: all}
	export.ExportDB(conf, &option)
}
